const jwtUtil = require('../utils/jwtUtils')
const tools = require('../utils/tools')
module.exports = class teacher_dao extends require('../model/teacher_mod') {
  // 获取请假条和总数量
  static async getLeave(req, res) {
    let verify = await jwtUtil.verifysync(req.query.token, global.globalKey)
    if (verify.err == "error") {
      return res.json(verify.msg)
    }
    let classArr = verify.classes.split(";")
    let {
      currPage,
      pageSize
    } = req.query
    let data = await this.getLeaveMod(classArr, currPage, pageSize)
    let total = await this.getLeaveTotal(classArr)
    res.json({
      data,
      total: total[0].count
    })

  }

  // 获取用户的请假审批与数量
  static async getUserLeave(req, res) {
    let verify = await jwtUtil.verifysync(req.query.token, global.globalKey)
    if (verify.err == "error") {
      return res.json(verify.msg)
    }
    let u_id = verify.id
    let {
      currPage,
      pageSize
    } = req.query
    let data = await this.getUserLeaveMod(u_id, currPage, pageSize)
    let total = await this.getUserLeaveTotal(u_id)
    res.json({
      data,
      total: total[0].count
    })
  }

  // 当前请假单状态审批
  static async upLeaveState(req, res) {
    let {
      l_id,
      upState
    } = req.query
    let results = await this.upLeaveStateMod(l_id, upState)
    res.json(results)
  }

  // 根据班级名称 获取班级id
  static async getCidByCname(req, res) {
    let cname = req.query.cname
    // console.log(cname);
    let result = await this.getCidByCnameMod(cname)
    // console.log(result);
    res.json(result[0].c_id)
  }

  // 获取风险学生
  static async getRiskedPeoplePage(req, res) {
    let {
      pageSize,
      currPage
    } = req.query
    let now = tools.getDate19();
    let begin = now.slice(0, 11) + "00:00:00";
    let end = now.slice(0, 11) + "23:59:59";
    let data = await this.getRiskedPeoplePageMod(begin, end, pageSize, currPage)
    let total = await this.getRiskedPeopleTotal(begin, end)

    res.json({
      data,
      total: total[0].count
    })
  }

  // 获取经过高风险地区学生
  static async getDangerPeoplePage(req, res) {
    let {
      pageSize,
      currPage
    } = req.query
    let now = tools.getDate19();
    let begin = now.slice(0, 11) + "00:00:00";
    let end = now.slice(0, 11) + "23:59:59";
    let data = await this.getDangerPeoplePageMod(begin, end, pageSize, currPage)
    let total = await this.getDangerPeoplePageTotal(begin, end)

    res.json({
      data,
      total: total[0].count
    })
  }

}